import 'package:flutter/material.dart';
import '../../utils/screenAdapter.dart';

class PassTextField extends StatelessWidget {
  final String hintText;
  final Function(String) onChanged;
  final bool hasBorder;
  final TextEditingController? controller;
  final bool passwordInput;
  const PassTextField({
    super.key,
    required this.hintText,
    required this.onChanged,
    this.hasBorder = false,
    this.controller,
    this.passwordInput = false, //  默认为false，表示不加密
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: ScreenAdapter.width(20)),
      height: ScreenAdapter.height(140),
      decoration: BoxDecoration(
        color: hasBorder ? Colors.transparent : Colors.black12,
        border: hasBorder
            ? Border(bottom: BorderSide(color: Colors.black12, width: 1))
            : Border(bottom: BorderSide.none),
        borderRadius: hasBorder
            ? BorderRadius.circular(0)
            : BorderRadius.circular(40),
      ),
      alignment: Alignment.center, // 需要设置外层对齐方式，否则内层宽度失效
      child: TextField(
        obscureText: passwordInput, // 隐藏输入内容
        obscuringCharacter: "*", // 隐藏字符
        controller: controller,
        keyboardType: TextInputType.number, // 设置键盘弹起类型
        cursorColor: Colors.black45, // 设置光标颜色
        onChanged: onChanged,
        style: const TextStyle(color: Colors.black45), // 设置输入框输入的文本颜色
        decoration: InputDecoration(
          hintText: hintText, // 设置输入框的提示文本--相当于placeholder
          hintStyle: const TextStyle(color: Colors.black45), // 设置提示文本的颜色
          border: InputBorder.none, // 去掉输入框默认下划线
        ),
      ),
    );
  }
}
